﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

namespace SyncCuringData
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        static void Main(string[] args)
        {
            //加载log4net配置文件
            var filepath = AppDomain.CurrentDomain.BaseDirectory + "\\Configs\\log4net.config";
            log4net.Config.XmlConfigurator.Configure(new FileInfo(filepath));
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[] { new SyncCuringDataService() };
            ServiceBase.Run(ServicesToRun);

            ////加载log4net配置文件
            //var filepath = AppDomain.CurrentDomain.BaseDirectory + "\\Configs\\log4net.config";
            //log4net.Config.XmlConfigurator.Configure(new FileInfo(filepath));
            
            ////如果传递了参数 s 就启动服务
            //if (args.Length > 0 && args[0] == "s")
            //{
            //    ServiceBase[] ServicesToRun;
            //    ServicesToRun = new ServiceBase[] { new SyncDataService() };
            //    ServiceBase.Run(ServicesToRun);
            //}
            //else
            //{
            //    Console.WriteLine("这是Windows应用程序");
            //    Console.WriteLine("请选择，[1]安装服务 [2]卸载服务 [3]退出");
            //    var rs = int.Parse(Console.ReadLine());
            //    string strServiceName = "SyncCuringService";
            //    switch (rs)
            //    {
            //        case 1:
            //            //取当前可执行文件路径，加上"s"参数，证明是从windows服务启动该程序
            //            var path = Process.GetCurrentProcess().MainModule.FileName + " s";
            //            Process.Start("sc", "create " + strServiceName + " binpath= \"" + path + "\" displayName=固化数据同步服务 start= auto");
            //            Console.WriteLine("安装成功");
            //            ServiceBase[] ServicesToRun;
            //            ServicesToRun = new ServiceBase[] { new SyncDataService() };
            //            ServiceBase.Run(ServicesToRun);
            //            Console.Read();
            //            break;
            //        case 2:
            //            Process.Start("sc", "delete " + strServiceName + "");
            //            Console.WriteLine("卸载成功");
            //            Console.Read();
            //            break;
            //        case 3: break;
            //    }
            //}
        }
    }
}
